<?php
class User_login extends CI_Controller
{
    public function __construct(){
        parent::__construct();
        $this->load->model('user_model');
        $this->template->set_template('login');
        
         
    }
    public function login(){
         $this->form_validation->set_rules(array(
          array('field' => 'user_email', 'label' => 'Email', 'rules' => 'trim|required|valid_email'),
          array('field' => 'user_password', 'label' => 'Password', 'rules' => 'trim|required')
         ));
         if ($this->form_validation->run($this)==FALSE)
        {
            $this->template->write_view('content','user_login','');
            $this->template->render();
        }else{
            $cond['user_email']=$this->input->post('user_email');
            $cond['user_password']=MD5($this->input->post('user_password'));
            $r=$this->user_model->get_users($cond)->num_rows();
          
            if($r>0){
                $this->session->set_userdata('user_id',$r);   
                         $this->template->set_template('default');
                $this->template->write_view('content','home','');
                $this->template->render();
            }
                
            
        }
    }    
   function logout(){
        $this->session->unset_userdata('user_id');        
         $this->template->write_view('content', 'user_login', '', $overwrite = FALSE);
         $this->template->render();
            //$this->template->render();
    }
} 
?>